#include<iostream>
#include <sys/types.h>
#include <unistd.h>
using namespace std;
int main()
{
//	cout<<"pid:"<<getpid()<<endl;
//	cout<<"ppid:"<<getppid()<<endl;
	int ret=fork();
	int count=0;
	if(ret ==0)//子进程
	{
	   for(int i=0;i<10000;i++)
	   {
		count++;
		cout<<"我是子进程"<<" "<<"父进程ID："<<getppid()<<" "<<"进程ID："<<getpid()<<"count的值为："<<count<<endl;
		sleep(0.5);
	   }
	}
	else if(ret >0)//父进程
	{
		for(int i=0;i<10000;i++)
		{
		  count++;
		  cout<<"我是父进程"<<" "<<"父进程ID："<<getppid()<<" "<<"进程ID:"<<getpid()<<"count的值为："<<count<<endl;
		  sleep(0.5);
		}
	}
	cout<<"count的总和为："<<count<<endl;
	return 0;
}
